package com.cc.controller;

import com.cc.entity.Cart;
import com.cc.entity.ChildrenCategory;
import com.cc.entity.ParentCategory;
import com.cc.entity.Produce;
import com.cc.service.CommodityService;
import com.cc.util.JsonResult;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program:
 * @ClassName:
 * @description:
 * @author: zgc
 * @date:
 * @Version 1.0
 **/
@RestController
@RefreshScope
public class CommodityController {
    @Resource
    private CommodityService commodityService;

    @RequestMapping("/toSelectCart")
    public JsonResult toSelectCart(Integer userId) {
        List<Cart> list = commodityService.selectCart(userId);
        return JsonResult.success(list);
    }

    @RequestMapping("/toSelectProduce")
    public JsonResult toSelectProduce(Integer produceId) {
        Produce produce = commodityService.selectProduce(produceId);
        return JsonResult.success(produce);
    }

    @RequestMapping("/toSelectParentCategory")
    public JsonResult toSelectParentCategory(ParentCategory parentCategory) {
        List<ParentCategory> parentCategoryList = commodityService.selectParentCategory(parentCategory);
        return JsonResult.success(parentCategoryList);
    }

    @RequestMapping("/toSelectChildCategory")
    public JsonResult toSelectChildCategory(ChildrenCategory childrenCategory) {
        List<ChildrenCategory> childrenCategoryList = commodityService.selectChildrenCategory(childrenCategory);
        return JsonResult.success(childrenCategoryList);
    }

    @RequestMapping("toInsertChildCategory")
    public JsonResult toInsertChildCategory(ChildrenCategory childrenCategory) {
        Integer result = commodityService.insertChildrenCategory(childrenCategory);
        return JsonResult.success(result);
    }
}
